from datetime import datetime

# 字符串转换为日期
def demo_1():
    text = '2012-09-20'
    print(datetime.strptime(text, '%Y-%m-%d'))
    print(datetime.now())
    print(datetime.now() - datetime.strptime(text, '%Y-%m-%d'))
    print(parse_ymd(text))

def parse_ymd(s):
    year_s, mon_s, day_s = s.split('-')
    return datetime(int(year_s), int(mon_s), int(day_s))



if __name__ == '__main__':
    demo_1()